package com.java2207.group1.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.java2207.group1.common.LayuiPageVo;
import com.java2207.group1.mapper.FaultMapper;
import com.java2207.group1.pojo.Fault;
import com.java2207.group1.service.FaultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service("faultService")
public class FaultServiceImpl implements FaultService {
    @Autowired
    private FaultMapper faultMapper;
    @Override
    public LayuiPageVo<Fault> faultPageAll(Map<String, Object> params) {
        int page = Integer.parseInt(params.get("page") + "");
        int limit = Integer.parseInt(params.get("limit") + "");
        PageHelper.startPage(page,limit);

        List<Fault> faults = faultMapper.faultPageAll(params);
        PageInfo<Fault> faultPageInfo = new PageInfo<>(faults);

        LayuiPageVo<Fault> layuiPageVo = new LayuiPageVo<>();
        layuiPageVo.setCode(0);
        layuiPageVo.setMsg("分页列表数据");
        layuiPageVo.setCount(faultPageInfo.getTotal());//总记录数
        layuiPageVo.setData(faultPageInfo.getList());//分页的列表数据
        return layuiPageVo;
    }

    @Override
    public int delectFault(int id) {
        int i = faultMapper.delectFault(id);
        return i;
    }

    @Override
    public int addFault(Fault fault) {
        int i = faultMapper.addFault(fault);
        return i;
    }

    @Override
    public int updateFault(Fault fault) {
        int i = faultMapper.updateFault(fault);
        return i;
    }
}
